package cn.maihe.elg.operation.supports.electronicseal.anne.service.impl;

import cn.maihe.elg.operation.config.AnneSignConfig;
import cn.maihe.elg.operation.config.ElgConfig;
import cn.maihe.elg.operation.supports.electronicseal.anne.AnneServiceName;
import cn.maihe.elg.operation.supports.electronicseal.anne.BaseAnneSignService;
import cn.maihe.elg.operation.supports.electronicseal.anne.bean.annesign.contract.ContractDetailListRequest;
import cn.maihe.elg.operation.supports.electronicseal.anne.bean.annesign.contract.ContractDetailListRequestBody;
import cn.maihe.elg.operation.supports.electronicseal.anne.bean.annesign.contract.ContractDetailListResponse;
import cn.maihe.elg.operation.supports.electronicseal.anne.utils.annesign.ApiException;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Description 合同自动签署
 * @Author WJH
 * @Date 2021/08/13
 */
@Slf4j
@Service
public class ContractDetailListService extends BaseAnneSignService<ContractDetailListRequest, ContractDetailListResponse> {


    public ContractDetailListService(AnneSignConfig anneSignConfig, ElgConfig elgConfig) {
        super(anneSignConfig, elgConfig);
    }

    @Override
    protected AnneServiceName serviceName() {
        return AnneServiceName.contract_detail_list;
    }


    /**
     * 合同详情  todo 待整合到 查询合同详情合同状态处理
     *
     * @param anneSignContractId
     */
    public ContractDetailListResponse getContractDetail(Long anneSignContractId) {
        ContractDetailListRequest request = this.buildBaseReq();
        ContractDetailListRequestBody body = new ContractDetailListRequestBody();
        body.setContractIdList(Lists.newArrayList(anneSignContractId));
        //original：原始PDF文档，sign：签署中的PDF文档
        body.setPdfImgSourceType("sign");

        request.setBody(body);

        ContractDetailListResponse response = null;
        try {
            //todo
            response = this.doPost(request);
        } catch (Exception e) {
            log.error("获取合同详情异常:{}", e.getMessage(), e);
            throw new ApiException("获取合同详情异常:" + e.getMessage(), e);
        }
        return response;
    }


}
